package code

// Failure 错误时返回结构
type Failure struct {
	Code    int    `json:"code"`    // 业务码
	Message string `json:"message"` // 描述信息
}

type Success struct {
	Code    int    `json:"code"`    // 业务码
	Message string `json:"message"` // 描述信息
	Data    any    `json:"data"`    // 数据
}

func OK(data any) *Success {
	return &Success{
		Code:    0,
		Message: "success",
		Data:    data,
	}
}

func Err(code int, message string) *Failure {
	return &Failure{
		Code:    code,
		Message: message,
	}
}

const (
	ServerError        = 10101
	ParamBindError     = 10102
	JWTAuthVerifyError = 10103

	AdminCreateError = 20201
	AdminListError   = 20202
	AdminFirstError  = 20203
	AdminDeleteError = 20204
)

var zhCNText = map[int]string{
	ServerError:        "内部服务器错误",
	ParamBindError:     "参数信息错误",
	JWTAuthVerifyError: "JWT 授权验证错误",

	AdminCreateError: "创建管理员失败",
	AdminListError:   "获取管理员列表失败",
	AdminFirstError:  "获取单个管理员失败",
	AdminDeleteError: "删除管理员失败",
}

func Text(code int) string {
	return zhCNText[code]
}
